import { log } from "util";

/*
 * @Author: 观星 12334214+zfb12345@user.noreply.gitee.com
 * @Date: 2024-07-10 12:14:57
 * @LastEditors: 观星 12334214+zfb12345@user.noreply.gitee.com
 * @LastEditTime: 2024-07-10 13:11:53
 * @FilePath: \practicee:\graduatedev\my-graduation-project\my-graduation-project-uniapp\utils\http.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
let baseURL = 'http://localhost:10001';

export const http = (options) => {
	return new Promise((resolve, reject) => {
		 const token = uni.getStorageSync('token');  
		uni.request({
			url: baseURL + options.url, 
			method: options.method || {},
			data: options.data || {}, 
			headers: {
			    'token ': token || {}
			},
			success: (res) => {
				let {code,msg}=res.data
				switch(code){
					case 200:
					if(msg!=='OK'){
						uni.showToast({
							icon:'none',
							title:msg
						})
					}
					break;
					default :
					uni.showToast({
						icon:'none',
						title:msg || '请求异常'
					})
					reject(res)
					break
				}
				resolve(res.data)
			},
			// 这里的接口请求，如果出现问题就输出接口请求失败
			fail: (err) => {
				console.log(err)
				reject(err)
			}
		})
	})
}
